package com.czx.decorator.impl;

import com.czx.decorator.CommonCacheService;
import com.czx.util.JvmCacheUtil;
import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.stereotype.Service;

@Service
public class JvmCacheServiceImpl implements CommonCacheService {

    @Override
    public <T> T get(String key, Class<T> T, ProceedingJoinPoint proceedingJoinPoint) {
        T t = JvmCacheUtil.get(key, T);
        if (t != null) {
            return t;
        }
        try {
            Object o = proceedingJoinPoint.proceed();
            JvmCacheUtil.put(key, o);
            return (T) o;
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        return null;
    }

}
